import {esri} from '../esriAPI'
import {arcgisTools} from "../arcgisTools";

export const windyTest = {}
windyTest.mapLoaded = function() {
  var {FeatureLayer,HeatmapRenderer,esriRequest} = esri;
   esriRequest("./static/test/data.json",{responseType: "json"}).then(
      function(response) {
        var data = response.data;
        var features = [];
        for (var i = 0; i < data.length; i++)
        {
          features.push({
            geometry: {
              type: "point",
              x: data[i][4],
              y: data[i][5]
            },
            attributes: {
              ObjectID: i,//重要！！！
              value: data[i][6]
            }
          });
        }
        console.log(features)
        var heatmapRenderer = new HeatmapRenderer({
          blurRadius: 10,
          //颜色设置
          colorStops: [
            {ratio: 0, color: "rgba(0, 255, 150, 0)"},
            {ratio: 0.6, color: "rgb(250, 250, 0)"},
            {ratio: 0.85, color: "rgb(250, 150, 0)"},
            {ratio: 0.95, color: "rgb(255, 50, 0)"}],
          maxPixelIntensity: 100,
          minPixelIntensity: 0
        });

        var featureLayer = new FeatureLayer({
          source: features,//点数据集
          title: "热力图",
          objectIdField: "ObjectID",//重要！！！
          renderer: heatmapRenderer//渲染器
        });
        featureLayer.renderer= heatmapRenderer;
        arcgisTools.baseMap.applyMap("container", {layers: [featureLayer]})
        arcgisTools.baseMap.applyMapView("container")
      }, function(error) {
        console.log("Error: ", error.message);
      });
}
